package com.sugar.subscribe.course.module.business.service.coachvenue;

import cn.hutool.core.collection.CollUtil;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import com.sugar.subscribe.course.module.business.controller.admin.coachvenue.vo.*;
import com.sugar.subscribe.course.module.business.dal.dataobject.coachvenue.CoachVenueDO;
import com.sugar.subscribe.course.framework.common.pojo.PageResult;
import com.sugar.subscribe.course.framework.common.pojo.PageParam;
import com.sugar.subscribe.course.framework.common.util.object.BeanUtils;

import com.sugar.subscribe.course.module.business.dal.mysql.coachvenue.CoachVenueMapper;

import static com.sugar.subscribe.course.framework.common.exception.util.ServiceExceptionUtil.exception;
import static com.sugar.subscribe.course.framework.common.util.collection.CollectionUtils.convertList;
import static com.sugar.subscribe.course.framework.common.util.collection.CollectionUtils.diffList;
import static com.sugar.subscribe.course.module.business.enums.ErrorCodeConstants.*;

/**
 * 教练授课场地 Service 实现类
 *
 * @author Ysugar
 */
@Service
@Validated
public class CoachVenueServiceImpl implements CoachVenueService {

    @Resource
    private CoachVenueMapper coachVenueMapper;

    @Override
    public Long createCoachVenue(CoachVenueSaveReqVO createReqVO) {
        // 插入
        CoachVenueDO coachVenue = BeanUtils.toBean(createReqVO, CoachVenueDO.class);
        coachVenueMapper.insert(coachVenue);

        // 返回
        return coachVenue.getId();
    }

    @Override
    public void updateCoachVenue(CoachVenueSaveReqVO updateReqVO) {
        // 校验存在
        validateCoachVenueExists(updateReqVO.getId());
        // 更新
        CoachVenueDO updateObj = BeanUtils.toBean(updateReqVO, CoachVenueDO.class);
        coachVenueMapper.updateById(updateObj);
    }

    @Override
    public void deleteCoachVenue(Long id) {
        // 校验存在
        validateCoachVenueExists(id);
        // 删除
        coachVenueMapper.deleteById(id);
    }

    @Override
        public void deleteCoachVenueListByIds(List<Long> ids) {
        // 删除
        coachVenueMapper.deleteByIds(ids);
        }


    private void validateCoachVenueExists(Long id) {
        if (coachVenueMapper.selectById(id) == null) {
            throw exception(COACH_VENUE_NOT_EXISTS);
        }
    }

    @Override
    public CoachVenueDO getCoachVenue(Long id) {
        return coachVenueMapper.selectById(id);
    }

    @Override
    public PageResult<CoachVenueDO> getCoachVenuePage(CoachVenuePageReqVO pageReqVO) {
        return coachVenueMapper.selectPage(pageReqVO);
    }

}